<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php 
	$USER = getAccountUserObject();
	$ESCORT = $this->escort_entity->init('user_id',$USER->getId());
	$thread_id = $this->input->get('thread_id', 0);
	
	$this->escort_message_thread_entity->updateReadStatus($thread_id);
	$listAllMessages = $this->escort_message_thread_entity->listAllMessagesOfThread($thread_id);	 
	$countUnread = $this->escort_message_thread_entity->countAllUnreadMessagesOfUser($ESCORT->getId(),USER_TYPE_ESCORT);	
	$countUnreadThread = $this->escort_message_thread_entity->countAllUnReadMessage($thread_id);	
?>
	
	<style>
		.message-refresh{
			float:left;
			margin-bottom:5px;
		}
		.message-reply{
			float:left;
			margin-bottom:5px;
			margin-left:20px;
		}
		.thread-close{
			float:right;
			margin-bottom:5px;
			margin-right:5px;
		}
	</style>
	
	<div class="dashboard-info-right">
		<div class="message-refresh">
			<a href="javascript:void(0);" onclick="return loadMessageOfThread(<?php echo $thread_id;?>);"><?php echo language_translate('support_label_refresh');?></a>
		</div>
		<div class="message-reply">
			<a href="javascript:void(0);" onclick="return replyMessageOfThread(<?php echo $thread_id;?>,'<?php echo $USER->getUserName();?>');"><?php echo language_translate('support_label_reply');?></a>
		</div>
		<div class="thread-close">
			<a href="javascript:void(0);" onclick="return closeMessageOfThread(<?php echo $thread_id;?>);"><?php echo language_translate('support_label_closed_thread_message');?></a>
		</div>
	</div>	
	<div class="clear"></div>
	
	 <?php $i=0; foreach($listAllMessages as $item): ?>
		<?php 
			$read_class = ($item->read == 1) ? 'read':'unread';
			$title = ($item->read == 1) ? language_translate('support_label_title_mark_unread'):language_translate('support_label_title_mark_read'); 
			$css_class = ($read_class == 'unread') ? 'unread_conversation':'';
		?>
		<?php if($i != 0):?>
		<div class="dashboard-info-right thread-item <?php echo $css_class;?> message_item_<?php echo $item->id;?>" rel="<?php echo $item->id;?>">
			<div class="item-name"><?php echo $item->sender;?></div>
			<div class="clear"></div>
			<div class="item-message">
				<?php echo $item->message;?>
			</div>	
			<div class="item-info-right">
				<div class="item-date"><?php echo sysDateFormat($item->sent_time,DATE_FORMAT);?></div>
				<div class="item-read-unread mark-item <?php echo $read_class;?>" title="<?php echo $title;?>" rel="<?php echo $item->id;?>" ></div>	
				<div class="item-delete delete" title="<?php echo language_translate('support_label_title_delete');?>" rel="<?php echo $item->id;?>" ></div>		
			</div>	
		</div>
		<div class="clear"></div>
		<?php endif; $i++;?>
	<?php endforeach;?>
	

<script type="text/javascript">
	var UNREAD = <?php echo $countUnread;?>;
	var UNREAD_THREAD = <?php echo $countUnreadThread;?>;
	var MODE = 'message';
</script>

<?php exit; ?>